﻿import React, {Component} from 'react';
import axios from 'axios'
import DingdanList from '../../components/dingdan/dingdanList'

import {queryOrdinaryOrderByMore} from '../../utils/api'


class Putongdingdan extends Component {
    constructor() {
        super();
        this.state={
            data:'暂无数据',
            data2:'暂无数据',
            leixing:1,
            phone:''
        }
    }

    componentDidMount() {
        this.putongDingdan({order_type_id:1})
        this.pintuanDingdan({order_type_id:2})
    }

    putongDingdan(item){
        axios({
            url:queryOrdinaryOrderByMore,
            method:'post',
            data:item
        }).then(data=>{
            console.log(data)
            if (data.data.code===200){
                this.setState({
                    data:data.data.data
                })
            }else{
                this.setState({
                    data:'暂无数据'
                })
            }
        })
    }
    pintuanDingdan(item){
        axios({
            url:queryOrdinaryOrderByMore,
            method:'post',
            data:item
        }).then(data=>{
            console.log(data)
            if (data.data.code===200){
                this.setState({
                    data2:data.data.data
                })
            }else{
                this.setState({
                    data2:'暂无数据'
                })
            }
        })
    }

    tiaojianSearch=(val)=>{
        val['order_type_id']=this.state.leixing
        console.log(val)
        if (this.state.leixing==1){
            this.putongDingdan(val)
        }else {
            this.pintuanDingdan(val)
        }
    }
    dingdanType=(val)=>{
        console.log(val)
        this.setState({
            leixing:parseInt(val)
        })
    }
    xiangQing=(val,text)=>{
        console.log(val)
        // console.log(text)
        // this.props.history.push({ pathname: '/Index/About/About4', state: { data: val } })
    }
    chongZhi=(e)=>{
        const value={}
        this.tiaojianSearch(value)
        this.setState({
            phone:''
        })
    }


    render() {
        // console.log(this.state.data2)
        const dingdanliebiao=this.state.data&&this.state.data2?<DingdanList.DingdanLieBiao
            dingdanLeixing={this.dingdanType}
            dingdandata={this.state.data}
            dingdandata2={this.state.data2}
            xiangQing={this.xiangQing}
            history={this.props.history}/>:''

        return (
            <div>
                <DingdanList.DingdanData data={this.state.data}/>
                <DingdanList.DingdanSaiXuan data={this.state.phone} search={this.tiaojianSearch} chongzhi={this.chongZhi}/>
                {dingdanliebiao}
            </div>
        );
    }
}

export default Putongdingdan;